home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / epuptm17.zip / DVUPTIME.C next >
C/C++ Source or Header  |  1994-01-27  |  2KB  |  97 lines

  1. #ifndef __TINY__
  2. #error Use TINY memory model--Don't forget to turn off debug info
  3. #endif
  4.  
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <dir.h>
  8. #include <time.h>
  9. #include <stdlib.h>
  10.  
  11. void 
  12. main(void);
  13. void 
  14. writeout(void);
  15.  
  16. char            filename[255];
  17. struct ffblk    ffblk;
  18. struct time     curtime;
  19. struct date     curdate;
  20. struct tm       old, *new;
  21. time_t          thetime;
  22. int             sec, min, day, hour;
  23. char            bday[4], bmon[4], ampm = 'a';
  24. int             bdate, bhour, bmin, bsec, byear;
  25.  
  26. void 
  27. main(void)
  28. {
  29.     strcpy(filename, searchpath("uptime.exe"));
  30.     writeout();
  31.     printf("\n\nStrike Any Key To Continue...");
  32.     fcloseall();
  33.     getch();
  34. }                /* main */
  35.  
  36.  
  37. void
  38. writeout(void)
  39. {
  40.    char tz[257],*oldtz;
  41.  
  42.    tz[0]='\0';
  43.    oldtz=getenv("TZ");
  44.    if(oldtz!=NULL){
  45.      strcat(tz,"TZ=");
  46.      putenv(tz);
  47.    }
  48.  
  49.    findfirst(filename, &ffblk, FA_DIREC);
  50.    old.tm_sec = 2 * (ffblk.ff_ftime & 31);
  51.    old.tm_min = (ffblk.ff_ftime & 2016) >> 5;
  52.    old.tm_hour = (ffblk.ff_ftime & 63488) >> 11;
  53.    old.tm_mday = (ffblk.ff_fdate & 31);
  54.    old.tm_mon = ((ffblk.ff_fdate & 480) >> 5) - 1;
  55.    old.tm_year = ((ffblk.ff_fdate & 65024) >> 9) + 80;
  56.    mktime(&old);
  57.  
  58.    thetime = time(NULL);
  59.    new = localtime(&thetime);
  60.  
  61.    sec = (*new).tm_sec - old.tm_sec;
  62.    min = (*new).tm_min - old.tm_min;
  63.    if (sec < 0) {
  64.       sec += 60;
  65.       min--;
  66.    }
  67.    hour = (*new).tm_hour - old.tm_hour;
  68.    if (min < 0) {
  69.       min += 60;
  70.       hour--;
  71.    }
  72.    day = (*new).tm_yday - old.tm_yday + (365 * ((*new).tm_year - old.tm_year));
  73.    if (hour < 0) {
  74.       hour += 24;
  75.       day--;
  76.    }
  77.    sscanf(asctime(&old), "%3s %3s %d %d:%d:%d %d", bday, bmon, &bdate, &bhour, &bmin, &bsec, &byear);
  78.    if (bhour >= 12) {
  79.       bhour -= 12;
  80.       ampm = 'p';
  81.    }
  82.    if (bhour == 0)
  83.       bhour = 12;
  84.    if (day < 0)
  85.       printf("Error:  System clock has been changed since bootup");
  86.    else if (day != 0)
  87.       printf("System launched at %2.2d:%2.2d:%2.2d%cm on %s, %s %d, %d\nUp for %d day(s), %2.2d:%2.2d:%2.2d", bhour, bmin, bsec, ampm, bday, bmon, bdate, byear, day, hour, min, sec);
  88.    else
  89.       printf("System launched at %2.2d:%2.2d:%2.2d%cm on %s, %s %d, %d\nUp for %2.2d:%2.2d:%2.2d", bhour, bmin, bsec, ampm, bday, bmon, bdate, byear, hour, min, sec);
  90.  
  91.    if(oldtz!=NULL){
  92.      strcpy(tz,oldtz);
  93.      putenv(tz);
  94.    }
  95.  
  96. }
  97.